package com.wchat.bean.model;

import com.wchat.bean.model.body.AckBody;
import com.wchat.bean.model.body.ChatMsgBody;
import com.wchat.bean.model.body.EventBody;
import com.wchat.bean.model.enums.ChatTypeEm;
import com.wchat.bean.model.enums.HeaderTypeEm;
import com.wchat.bean.model.enums.TypeEm;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author : willian fu
 * @date : 2021/8/26
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MsgPayload {

    private HeaderTypeEm header;

    private TypeEm type;

    private Object body;

    public Long getMsgId(){
        if (body instanceof ChatMsgBody){
            return Long.parseLong(((ChatMsgBody) body).getMsgId());
        }else if (body instanceof AckBody){
            return Long.parseLong(((AckBody) body).getMsgId());
        }
        return null;
    }

    public Boolean isGroup(){
        if (body instanceof ChatMsgBody){
            return ChatTypeEm.GROUP.equals(((ChatMsgBody) body).getType());
        }else {
            return false;
        }
    }
}
